from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-11-30 14:03:15.825106
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 30, Nov, 2021
Time: 14:03:21
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.2882
Nobs: 491.000 HQIC: -47.7554
Log likelihood: 5617.81 FPE: 1.34571e-21
AIC: -48.0574 Det(Omega_mle): 1.12239e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.385194 0.083403 4.618 0.000
L1.Burgenland 0.094495 0.044651 2.116 0.034
L1.Kärnten -0.116237 0.022888 -5.078 0.000
L1.Niederösterreich 0.164345 0.092716 1.773 0.076
L1.Oberösterreich 0.125833 0.094263 1.335 0.182
L1.Salzburg 0.281487 0.047888 5.878 0.000
L1.Steiermark 0.018015 0.061944 0.291 0.771
L1.Tirol 0.107714 0.049915 2.158 0.031
L1.Vorarlberg -0.085083 0.043966 -1.935 0.053
L1.Wien 0.031502 0.084033 0.375 0.708
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.027009 0.185250 0.146 0.884
L1.Burgenland -0.050324 0.099177 -0.507 0.612
L1.Kärnten 0.036599 0.050838 0.720 0.472
L1.Niederösterreich -0.216869 0.205936 -1.053 0.292
L1.Oberösterreich 0.472892 0.209371 2.259 0.024
L1.Salzburg 0.311025 0.106366 2.924 0.003
L1.Steiermark 0.097843 0.137586 0.711 0.477
L1.Tirol 0.308177 0.110868 2.780 0.005
L1.Vorarlberg 0.008842 0.097654 0.091 0.928
L1.Wien 0.015792 0.186649 0.085 0.933
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.233242 0.042431 5.497 0.000
L1.Burgenland 0.092015 0.022716 4.051 0.000
L1.Kärnten -0.004595 0.011645 -0.395 0.693
L1.Niederösterreich 0.222626 0.047170 4.720 0.000
L1.Oberösterreich 0.163438 0.047956 3.408 0.001
L1.Salzburg 0.034753 0.024363 1.426 0.154
L1.Steiermark 0.025242 0.031514 0.801 0.423
L1.Tirol 0.075473 0.025394 2.972 0.003
L1.Vorarlberg 0.055992 0.022368 2.503 0.012
L1.Wien 0.103648 0.042752 2.424 0.015
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.176464 0.041147 4.289 0.000
L1.Burgenland 0.042284 0.022029 1.919 0.055
L1.Kärnten -0.012101 0.011292 -1.072 0.284
L1.Niederösterreich 0.146408 0.045742 3.201 0.001
L1.Oberösterreich 0.339567 0.046505 7.302 0.000
L1.Salzburg 0.098309 0.023626 4.161 0.000
L1.Steiermark 0.109617 0.030560 3.587 0.000
L1.Tirol 0.085052 0.024626 3.454 0.001
L1.Vorarlberg 0.054418 0.021691 2.509 0.012
L1.Wien -0.039853 0.041458 -0.961 0.336
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180776 0.079631 2.270 0.023
L1.Burgenland -0.042053 0.042632 -0.986 0.324
L1.Kärnten -0.036100 0.021853 -1.652 0.099
L1.Niederösterreich 0.122311 0.088523 1.382 0.167
L1.Oberösterreich 0.177641 0.090000 1.974 0.048
L1.Salzburg 0.252773 0.045722 5.528 0.000
L1.Steiermark 0.075340 0.059143 1.274 0.203
L1.Tirol 0.130068 0.047658 2.729 0.006
L1.Vorarlberg 0.107128 0.041978 2.552 0.011
L1.Wien 0.036253 0.080233 0.452 0.651
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079642 0.063122 1.262 0.207
L1.Burgenland 0.016266 0.033794 0.481 0.630
L1.Kärnten 0.051215 0.017323 2.957 0.003
L1.Niederösterreich 0.178329 0.070171 2.541 0.011
L1.Oberösterreich 0.337728 0.071341 4.734 0.000
L1.Salzburg 0.050626 0.036243 1.397 0.162
L1.Steiermark -0.007799 0.046881 -0.166 0.868
L1.Tirol 0.124033 0.037777 3.283 0.001
L1.Vorarlberg 0.058620 0.033275 1.762 0.078
L1.Wien 0.113038 0.063599 1.777 0.076
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179791 0.076703 2.344 0.019
L1.Burgenland 0.011098 0.041065 0.270 0.787
L1.Kärnten -0.060644 0.021050 -2.881 0.004
L1.Niederösterreich -0.113448 0.085268 -1.330 0.183
L1.Oberösterreich 0.225378 0.086691 2.600 0.009
L1.Salzburg 0.036615 0.044041 0.831 0.406
L1.Steiermark 0.266385 0.056968 4.676 0.000
L1.Tirol 0.488979 0.045905 10.652 0.000
L1.Vorarlberg 0.072204 0.040434 1.786 0.074
L1.Wien -0.103071 0.077283 -1.334 0.182
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.136649 0.084807 1.611 0.107
L1.Burgenland -0.012931 0.045403 -0.285 0.776
L1.Kärnten 0.063967 0.023274 2.748 0.006
L1.Niederösterreich 0.173877 0.094277 1.844 0.065
L1.Oberösterreich -0.075157 0.095849 -0.784 0.433
L1.Salzburg 0.222353 0.048694 4.566 0.000
L1.Steiermark 0.133828 0.062987 2.125 0.034
L1.Tirol 0.051126 0.050755 1.007 0.314
L1.Vorarlberg 0.142498 0.044706 3.187 0.001
L1.Wien 0.167451 0.085447 1.960 0.050
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.462514 0.046773 9.889 0.000
L1.Burgenland -0.001670 0.025041 -0.067 0.947
L1.Kärnten -0.013114 0.012836 -1.022 0.307
L1.Niederösterreich 0.177459 0.051995 3.413 0.001
L1.Oberösterreich 0.264378 0.052863 5.001 0.000
L1.Salzburg 0.018387 0.026856 0.685 0.494
L1.Steiermark -0.013382 0.034738 -0.385 0.700
L1.Tirol 0.069130 0.027992 2.470 0.014
L1.Vorarlberg 0.056524 0.024656 2.292 0.022
L1.Wien -0.018196 0.047126 -0.386 0.699
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.025755 0.089457 0.152304 0.137073 0.063062 0.081715 0.015543 0.206943
Kärnten 0.025755 1.000000 -0.038292 0.127593 0.046914 0.072182 0.456420 -0.082438 0.093998
Niederösterreich 0.089457 -0.038292 1.000000 0.276793 0.094712 0.252655 0.046845 0.142258 0.242295
Oberösterreich 0.152304 0.127593 0.276793 1.000000 0.186062 0.287094 0.159819 0.126146 0.173291
Salzburg 0.137073 0.046914 0.094712 0.186062 1.000000 0.119950 0.058439 0.109629 0.060247
Steiermark 0.063062 0.072182 0.252655 0.287094 0.119950 1.000000 0.131334 0.087110 0.004815
Tirol 0.081715 0.456420 0.046845 0.159819 0.058439 0.131334 1.000000 0.063124 0.128445
Vorarlberg 0.015543 -0.082438 0.142258 0.126146 0.109629 0.087110 0.063124 1.000000 -0.011506
Wien 0.206943 0.093998 0.242295 0.173291 0.060247 0.004815 0.128445 -0.011506 1.000000